<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong> {{ leftCount }}</strong></span
    >
    <ul class="filters">
      <li>
        <a @click="$emit('changeType', 'all')" :class="{ selected: type == 'all' }" href="javascript:;">全部</a>
      </li>
      <li>
        <a @click="$emit('changeType', 'no')" :class="{ selected: type == 'no' }" href="javascript:;">未完成</a>
      </li>
      <li>
        <a @click="$emit('changeType', 'yes')" :class="{ selected: type == 'yes' }" href="javascript:;">已完成</a>
      </li>
    </ul>
    <button class="clear-completed" v-show="isShowCliear" @click="clear">清除已完成</button>
  </footer>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      required: true
    },
    type: String
  },
  computed: {
    leftCount() {
      return this.list.filter((item) => !item.isDone).length
    },
    isShowCliear() {
      return this.list.some((item) => item.isDone)
    }
  },
  methods: {
    clear() {
      this.$emit('clear')
    }
  }
}
</script>
